precision mediump float;

uniform sampler2D u_texture_0;	//fire
uniform sampler2D u_texture_1;	//displacement map
uniform sampler2D u_texture_2;	//blend map
uniform float u_time;

varying vec2 v_uv;

void main()
{
	float dMax = 0.15; //if dMax is greater, the fire will become more different to the original fire.
	vec2 disp = texture2D(u_texture_1, vec2(v_uv.x, v_uv.y + u_time)).rg;
	vec2 offset = (2.0 * disp - 1.0) * dMax;
	vec2 uv_disp = v_uv + offset;
	vec4 fireColor = texture2D(u_texture_0, uv_disp);
	float alpha = texture2D(u_texture_2, v_uv).r;
	
	vec4 Cobj = fireColor * (1.0, 1.0, 1.0, alpha);
	
	gl_FragColor = Cobj;
	
	if (gl_FragColor.a < 0.1)
		discard;	// Discard the fragments which are so opaque
}